package Views.TableModels;

import Models.*;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/**
 * @author Thomas
 */
public class ItemTableModel extends DefaultTableModel
{
	private ArrayList<Item> items;

	public ItemTableModel()
	{
		this.items = new ArrayList<Item>();
	}

	public ItemTableModel(ArrayList<Item> items)
	{
		this.items = items;
	}

	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}

	public void setData(ArrayList<Item> items)
	{
		this.items = items;
		fireTableDataChanged();
	}

	public ArrayList<Item> getData()
	{
		return this.items;
	}

	@Override
	public int getColumnCount()
	{
        return 4;
	}

	@Override
	public int getRowCount()
	{
		if(this.items == null)
		{
			return 0;
		}
		else
		{
			return this.items.size();
		}
	}

	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Navn";
				break;
			case 2:
				columnName = "Producent";
				break;
			case 3:
				columnName = "Pris";
				break;
		}
		return columnName;
	}

	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.items.get(row).getItemNo();
				break;
			case 1:
				value = this.items.get(row).getName();
				break;
			case 2:
				value = this.items.get(row).getManufacturer();
				break;
			case 3:
				value = this.items.get(row).getPrice();
				break;
		}
		return value;
	}
}
